import '../helper/dioHelper2.dart';

class ScsqSK {
  int ID;
  String TM;
  double H;
  double Q;
  double R;
  String P;

  ScsqSK(this.ID, this.TM, this.H, this.Q, this.R, this.P);
  ScsqSK.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        TM = json["TM"],
        H = json["H"]*1.0,
        Q = json["Q"]*1.0,
        R = json["R"]*1.0,
        P = json["P"];
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'TM': TM,
        'H': H,
        'Q': Q,
        'R': R,
        'P': P,
      };
  static Future<bool> Add(ScsqSK x1) async {
    var response = await DioHelper.Post("/ScsqSK/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(ScsqSK x1) async {
    var response = await DioHelper.Post("/ScsqSK/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(ScsqSK x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/ScsqSK/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<ScsqSK?> Get(String where, dynamic data) async {
    var response = await DioHelper.Post("/ScsqSK/GetByWhere", {
      "Where": where,
      "obj": data,
    });

    if (response.statusCode == 200) return new ScsqSK.fromJson(response.data);
    return null;
  }

  static Future<List<ScsqSK>> GetList(
      String where, dynamic data, int pageIndex, int pageSize) async {
    var response = await DioHelper.Post("/ScsqSK/GetListByWhere", {
      "Where": where,
      "obj": data,
      "PageIndex": pageIndex,
      "PageSize": pageSize,
    });
    var list1 = <ScsqSK>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new ScsqSK.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<ScsqSK>> GetAllList() async {
    var response = await DioHelper.Get("/ScsqSK/GetAllList", {});
    var list1 = <ScsqSK>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new ScsqSK.fromJson(x));
      }
    }
    return list1;
  }


   static Future<List<ScsqSK>> GetListByTM(String t1,t2) async {
    var response = await DioHelper.Get("/SdzxData/GetSKHourListByTM?TM1="+t1+"&TM2="+t2, {});
    var list1 = <ScsqSK>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new ScsqSK.fromJson(x));
      }
    }
   // print(list1);
    return list1;
  }
}
